package com.wlc.exception.demo03;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 银行账户
 * @date 2021-07-08 16:06
 */
public class Account {
    /**
     * 余额
     */
    double balance;

    public Account(double balance) {
        this.balance = balance;
    }

    public Account() {
    }

    /**
     * 获取余额
     */
    double getBalance() {
        return balance;
    }

    /**
     * 存钱
     */
    void deposit(double amount) {
        balance += amount;
    }

    /**
     * 取钱
     */
    void withdraw(double amount) throws OverdraftException {
        if (this.balance < amount) {
            throw new OverdraftException("余额不足。。", amount - this.balance);
        }
        this.balance -= amount;
    }
}
